;
; SYSLIB Module Name:  SPADC
; Author:  Richard Conn
; SYSLIB Version Number:  2.0
; Module Version Number:  1.0
; Module Entry Points:
;	PA3DC		PADC
; Module External References:
;	COUT
;

;
;  PA3DC --
;	PRINT REG A AS 3 DECIMAL CHARACTERS
;
	EXT	COUT

PA3DC::
	PUSH	PSW	; SAVE A
	PUSH	PSW
	XRA	A	; TURN OFF LEADING <SP> FLAG
	STA	LSFLG
	JMP	PADC1
;
;  PADC --
;	PRINT REG A AS DECIMAL CHARACTERS W/LEADING <SP> IN 3-CHAR FIELD
;
PADC::
	PUSH	PSW	; SAVE A
	PUSH	PSW
	MVI	A,1	; TURN ON LEADING <SP> FLAG
	STA	LSFLG
;  PRINT ROUTINE
PADC1:	POP	PSW	; GET A
	PUSH	B	; SAVE BC
	MVI	B,100	; PRINT HUNDREDS
	CALL	PAC	; PRINT A CHAR
	MVI	B,10	; PRINT TENS
	CALL	PAC
	ADI	'0'	; CONVERT TO ASCII
	CALL	COUT	; PRINT
	POP	B	; RESTORE BC
	POP	PSW	; RESTORE A
	RET

;  BUFFER
LSFLG:	DS	1	; LEADING <SP> FLAG

;  PRINT RESULT OF DIVISION OF A BY B W/LEADING <SP> (INTEGER DIVISION)
PAC:	MVI	C,0	; SET COUNT
PACL:	SUB	B	; COMPUTE COUNT
	JC	PACD
	INR	C	; INCR COUNT
	JMP	PACL
PACD:	ADD	B	; ADD B BACK IN
	PUSH	PSW	; SAVE A
	MOV	A,C	; GET COUNT
	ORA	A	; ZERO?
	JNZ	PACD1
	LDA	LSFLG	; CHECK FOR LEADING <SP>
	ORA	A	; 0 MEANS NO
	JZ	PACD1
	MVI	A,' '	; PRINT <SP>
	CALL	COUT
	POP	PSW	; RESTORE A
	RET
PACD1:	XRA	A	; A=0
	STA	LSFLG	; TURN OFF LEADING <SP> FLAG
	MOV	A,C	; GET COUNT
	ADI	'0'	; CONVERT TO DECIMAL
	CALL	COUT	; PRINT IT
	POP	PSW	; RESTORE A
	RET

	END
